#include "cmodel.h"

/**
 * @brief 均值池化 特征图 size 4x4
 * 例如: 输入 img_in[512,4,4]; 输出 img_out[512,1,1]
 * 
 * @param img 输入参数
 */
void avg_pool2d_4x4_inplace(featureMap  *img)
{
    // check args
    if (img->width != 4 || img->height != 4)
    {
        debug("wrong width or height or channel\n");
        return;
    }
    int CH = img->channels;
    int IW = img->width;
    int IH = img->height;

    img->width = 1;
    img->height = 1;

    float sum = 0;
    for (int ch = 0; ch < CH; ch++)
    {
        for (int i = 0; i < 16; i++)
        {   // img[ch] += img[ch][i]
            if (i == 0)        
                *(img->data + ch) = *(img->data + ch * IW * IH + i);
            else
                *(img->data + ch) += *(img->data + ch * IW * IH + i);
        }
        *(img->data + ch) /= 16;
    }
}
